home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11872 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  998 b 

  1. Path: solon.com!not-for-mail
  2. From: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 26 Mar 1996 18:56:14 -0600
  6. Organization: TU Wien
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4ja3ne$p6j@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. Reed R. Mangino <mangino@planet.net> writes:
  14.  
  15. |> 1) const int *p = 10;
  16.  
  17. A point not mentioned by earlier correct follow-ups is that
  18. 10 is being assigned to p here, and not to *p.  Assigning 10 to p
  19. is suspicious.  If you want to assign 10 to *p, you must make
  20. p point to an integer first.  Of course, you then can't, because *p is const.
  21. One way out of this problem is
  22.  
  23. const int secret = 10, *p = &secret;
  24.  
  25. The rule I use for const is that const binds to the left, unless it can't,
  26. then it binds to the right.  *const *p is a pointer to a constant
  27. pointer.
  28.  
  29. Konrad Schwarz
  30.